#include"stc.h"

int main()
{
	int Month=0;
	int Y=0; 	
	int y =0; 
	int day = 0;
	int Firstday; 
	int k = 0;
	int i = 0;
	int m = 0;
	int tday;
	int dmonth;
	while( Y < 1 || Y > 10000)
	{
		PutStr("Input Year(1-99999) : ");
	    Y = GetInt();
	}
	while(Month < 1 || Month > 12)
	{
		PutStr("\nInput Month(1-12) : ");
	    Month = GetInt();
	}

	dmonth = 30 * (Month == 4 || Month == 6 || Month == 9 || Month == 11)
		+ 31 * (Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12) 		
		+ (28 + (Y % 400 == 0 || (Y % 4 == 0 && Y % 100 != 0))) * (Month == 2);

	y=0;	
	while(y<Y)
	{	y=y+1;		
		k = k + (y % 400 == 0 || y % 4 == 0 && y % 100 != 0);
	}
	tday = k * 366 + (Y - k - 1) * 365;
	m = m + 1;
	while(m<Month)
	{
		tday = tday 
		+ 30 * (m == 4 || m == 6 || m == 9 || m == 11)
		+ 31 * (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)		
		+ (28 + (Y % 400 == 0 || (Y % 4 == 0 && Y % 100 != 0))) * (m == 2);

	}
	Firstday = (1 + (tday % 7)) % 7; 
	y = Firstday;
	PutStr("\nSu  Mo  Tu  We  Th  Fr  Sa\n");
	PutStr("----------------------------\n");	

	while(i>7)
	{
		PutStr("\n");
	    y = 0;
	while(i<Firstday)
	{
	PutStr("    ");
	i = i + 1;
	}
	day = day + 1;
	while(day < dmonth)
	{
	 PutStr("\n");
	if(day<9){
	PutInt(day);
	PutStr("  ");
	y = y + 1;
	      }
	else{
		PutStr(" ");
	    }
	}
	}

}